package com.zte.stats.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.stats.dao.IStatsPurchaseDao;
import com.zte.stats.model.StatsCFirm;
import com.zte.stats.model.StatsCPurchase;
import com.zte.stats.model.StatsPurchaseCondition;
import com.zte.stats.service.IStatsPurchaseService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatsPurchaseServiceImpl implements IStatsPurchaseService {

    @Autowired
    private IStatsPurchaseDao iStatsPurchaseDao;

    @Override
    public PageModel<StatsCFirm> queryCFirmListByCondition(PageModel<StatsCFirm> pageModel, StatsPurchaseCondition spc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsCFirm> statsCFirms = iStatsPurchaseDao.queryCFirm(spc);
        PageInfo<StatsCFirm> info = new PageInfo<StatsCFirm>(statsCFirms);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsCFirm>(info.getList()));
        return pageModel;
    }

    @Override
    public PageModel<StatsCPurchase> queryProductListByCondition(PageModel<StatsCPurchase> pageModel, StatsPurchaseCondition spc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsCPurchase> StatsCPurchases = iStatsPurchaseDao.queryCPurchase2(spc);
        PageInfo<StatsCPurchase> info = new PageInfo<StatsCPurchase>(StatsCPurchases);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsCPurchase>(info.getList()));
        return pageModel;
    }
}
